<!DOCTYPE html>
<html lang="en">
<head>
  <meta charset="UTF-8">
  <meta http-equiv="X-UA-Compatible" content="IE=edge">
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <title>Document</title>
</head>
<body>
  <script>
      let obj = {
            name: '张三',
            age: 22,
            like: ['rap', 'lol']
        }
       // console.log(typeof({}))
        function deepCope(num){
          // 判断传入的参数是否是数组和对象 不是直接抛出错误
          if(typeof(num)=='object'){
            let newNum = Array.isArray(num)?[]:{};
            for(var i in num){
              if(typeof(num[i])=='object'){
                newNum[i]=deepCope(num[i])
              }else{
                newNum[i]=num[i];
              }
            }
            return newNum
          }else{
            throw new Error('传入的参数有误！！！')
          }
        }
        newNum=deepCope(obj)
       console.log(newNum) 
  </script>
</body>
</html>